package com.universe.titan.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.universe.titan.common.entity.initial.User;
import com.universe.titan.common.util.MD5Util;
import com.universe.titan.service.UserService;
import com.universe.titan.vo.UserReqVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService {

    @Autowired
    private UserMapper userMapper;



    @Override
    public IPage<User> selectPageByUserVo(UserReqVo userVo) {
        Page page = new Page<>(userVo.getPageNum(), userVo.getPageSize());
        return userMapper.selectPageByUserVo(page,userVo);
    }

    @Override
    public boolean saveOrUpdateUser(UserReqVo req) {
        User user = new User();
        if (StringUtils.isNotBlank(req.getPassword())){
            req.setPassword(MD5Util.md5Hex(req.getPassword()));
        }
        BeanUtils.copyProperties(req,user);
        return saveOrUpdate(user);
    }

    @Override
    public void deleteUser(UserReqVo req) {
        userMapper.deleteUser(req);
    }




}
